import unittest
import datetime
from .case import Catgory, Discount


# 分类测试单元
class TestCatgory(unittest.TestCase):
    instance = None

    @classmethod
    def setUpClass(cls):
        cat = {
            '电子': {'ipad', 'iphone', '显示器', '笔记本电脑', '键盘'},
        }
        cls.instance = Catgory(cat)

    @classmethod
    def tearDownClass(cls):
        del cls.instance

    def test_get_cat_label(self):
        self.assertEqual(self.instance.get_cat_label_by_name('ipad'), '电子')
        self.assertEqual(self.instance.get_cat_label_by_name('xxx'), None)


# 折扣测试单元
class TestDiscount(unittest.TestCase):
    instance = None
    date = None

    @classmethod
    def setUpClass(cls):
        discount = {
            (11, 11): {'电子': 0.7},  # (月,日): [('品类',折扣)]
        }
        cls.instance = Discount(discount)
        cls.date = (11,11)

    @classmethod
    def tearDownClass(cls):
        del cls.instance

    def test_get_cat_label(self):
        self.assertEqual(self.instance.get_rate_by_date_cat(self.date, '电子'), 0.7)


if __name__ == '__main__':
    unittest.main()